<template>
  <div id="app">
    <Topbar :key="topKeyValue"></Topbar>
    <Header></Header>
    <router-view @updateKey="updateKeyFn" />
    <Footer></Footer>
    <Login v-show="isShowLoginModal"></Login>
    <Toast v-show="isShowToast"></Toast>
  </div>
</template>
<script>
import Header from "@/components/Header.vue";
import Topbar from "@/components/Topbar.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";
import { JingpinAPI } from "@/request/api.js";
import { mapState } from "vuex";
export default {
  data() {
    return {
      topKeyValue: 0,
    };
  },
  methods: {
    updateKeyFn() {
      this.topKeyValue++;
    },
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        if (oldVal != "/") {
          this.topKeyValue++;
        }
      },
    },
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  components: {
    Header,
    Topbar,
    Footer,
    Login,
    Toast,
  },
  async created() {
    console.log("环境变量", process.env.VUE_APP_MY_NAME);
    this.$eventBus.$on("eventTst", () => {
      this.topKeyValue++;
    });
  },
};
</script>
<style lang="less">
</style>
